//
//  MCCellInfo.m
//  shandianxiu
//
//  Created by delicious on 2017/11/25.
//  Copyright © 2017年 aojun. All rights reserved.
//

#import "MCCellInfo.h"
#import "UIView+Base.h"

@implementation MCCellInfo

+(MCCellInfo *)configForCellId:(NSString *)cellId Class:(Class)aClass Height:(CGFloat)cellHeight TableView:(UITableView *)tableView CellStyle:(UITableViewCellStyle)cellStyle
{
    return [MCCellInfo configForCellId:cellId Class:aClass InitCellBlock:nil Height:cellHeight TableView:tableView CellStyle:cellStyle IsBian:NO];
}

+(MCCellInfo *)configForCellId:(NSString *)cellId Class:(Class)aClass Height:(CGFloat)cellHeight TableView:(UITableView *)tableView
{
    return [MCCellInfo configForCellId:cellId Class:aClass InitCellBlock:nil Height:cellHeight TableView:tableView CellStyle:UITableViewCellStyleDefault IsBian:NO];
}

+(MCCellInfo *)configForCellId:(NSString *)cellId Class:(Class)aClass InitCellBlock:(initCellBlock)cellBlock Height:(CGFloat)cellHeight TableView:(UITableView *)tableView
{
   return [MCCellInfo configForCellId:cellId Class:aClass InitCellBlock:cellBlock Height:cellHeight TableView:tableView CellStyle:UITableViewCellStyleDefault IsBian:NO];
}
+(MCCellInfo *)configForCellId:(NSString *)cellId Class:(Class)aClass InitCellBlock:(initCellBlock)cellBlock Height:(CGFloat)cellHeight TableView:(UITableView *)tableView IsBian:(BOOL)isBiao
{
     return [MCCellInfo configForCellId:cellId Class:aClass InitCellBlock:cellBlock Height:cellHeight TableView:tableView CellStyle:UITableViewCellStyleDefault IsBian:isBiao];
}
+(MCCellInfo *)configForCellId:(NSString *)cellId Class:(Class)aClass Height:(CGFloat)cellHeight TableView:(UITableView *)tableView IsBian:(BOOL)isBiao
{
    return [MCCellInfo configForCellId:cellId Class:aClass InitCellBlock:nil Height:cellHeight TableView:tableView CellStyle:UITableViewCellStyleDefault IsBian:isBiao];
}
+(MCCellInfo *)configForCellId:(NSString *)cellId Class:(Class)aClass Height:(CGFloat)cellHeight TableView:(UITableView *)tableView CellStyle:(UITableViewCellStyle)cellStyle IsBian:(BOOL)isBiao
{
     return [MCCellInfo configForCellId:cellId Class:aClass InitCellBlock:nil Height:cellHeight TableView:tableView CellStyle:cellStyle IsBian:isBiao];
}

+(MCCellInfo *)configForCellId:(NSString *)cellId Class:(Class)aClass InitCellBlock:(initCellBlock)cellBlock TableView:(UITableView *)tableView CellStyle:(UITableViewCellStyle)cellStyle
{
    return [MCCellInfo configForCellId:cellId Class:aClass InitCellBlock:cellBlock Height:CGFLOAT_MIN TableView:tableView CellStyle:UITableViewCellStyleDefault IsBian:NO];
}

+(MCCellInfo *)configForCellId:(NSString *)cellId Class:(Class)aClass InitCellBlock:(initCellBlock)cellBlock Height:(CGFloat)cellHeight TableView:(UITableView *)tableView CellStyle:(UITableViewCellStyle)cellStyle IsBian:(BOOL)isBiao
{
    MCCellInfo *cellInfo = [tableView.cellConfigDic valueForKey:cellId];
    if (!cellInfo) {
        cellInfo = [[MCCellInfo alloc]init];
        cellInfo.cellId = cellId;
        cellInfo.aClass = aClass;
        cellInfo.cellStyle  = cellStyle;
        cellInfo.cellHeight = cellHeight;
        if (cellBlock) {
            cellInfo.initBlock = cellBlock;
        }
        [tableView.cellConfigDic setValue:cellInfo forKey:cellId];
    }
    if(isBiao)
    {
        cellInfo.cellHeight = cellHeight;
    }
    
    return cellInfo;
}



+(MCCellInfo *)configForCellId:(NSString *)cellId Class:(Class)aClass UpdateHeight:(updateHeight)cellHeight TableView:(UITableView *)tableView forIndexPath:(NSIndexPath *)indexPath  IsBian:(BOOL)isBiao;
{
   return [MCCellInfo configForCellId:cellId Class:aClass InitCellBlock:nil UpdateHeight:cellHeight TableView:tableView forIndexPath:indexPath CellStyle:UITableViewCellStyleDefault IsBian:isBiao];
}

+(MCCellInfo *)configForCellId:(NSString *)cellId Class:(Class)aClass UpdateHeight:(updateHeight)cellHeight TableView:(UITableView *)tableView  forIndexPath:(NSIndexPath *)indexPath CellStyle:(UITableViewCellStyle)cellStyle  IsBian:(BOOL)isBiao;
{
    return [MCCellInfo configForCellId:cellId Class:aClass InitCellBlock:nil UpdateHeight:cellHeight TableView:tableView forIndexPath:indexPath CellStyle:cellStyle IsBian:isBiao];
}

+(MCCellInfo *)configForCellId:(NSString *)cellId Class:(Class)aClass InitCellBlock:(initCellBlock)cellBlock UpdateHeight:(updateHeight)cellHeight TableView:(UITableView *)tableView forIndexPath:(NSIndexPath *)indexPath CellStyle:(UITableViewCellStyle)cellStyle IsBian:(BOOL)isBiao;
{
    if (kStringIsEmpty(cellId)==YES) {
        return nil;
    }
    
    MCCellInfo *cellInfo = [tableView.cellConfigDic valueForKey:cellId];
    if (!cellInfo) {
        cellInfo = [[MCCellInfo alloc]init];
        cellInfo.cellId = cellId;
        cellInfo.aClass = aClass;
        cellInfo.cellStyle  = cellStyle;
        if (cellBlock) {
            cellInfo.initBlock = cellBlock;
        }
        [tableView.cellConfigDic setValue:cellInfo forKey:cellId];
    }
    if (isBiao) {
        if (cellHeight) {
//            MainThreadPerformBlock(^{
                CGFloat h = cellHeight(cellId,tableView,indexPath);
                cellInfo.cellHeight = h;
//            });
        }
    }
    return cellInfo;
    
}

@end



@implementation MCHFViewInfo

+(MCHFViewInfo *)configForViewId:(NSString *)viewId Class:(Class)aClass Height:(CGFloat)viewHeight TableView:(UITableView *)tableView
{
    return [MCHFViewInfo configForViewId:viewId Class:aClass Height:viewHeight TableView:tableView IsBian:NO];
}

+(MCHFViewInfo *)configForViewId:(NSString *)viewId Class:(Class)aClass Height:(CGFloat)viewHeight TableView:(UITableView *)tableView IsBian:(BOOL)isBiao
{
    MCHFViewInfo *viewInfo = [tableView.viewConfigDic valueForKey:viewId];
    if (!viewInfo) {
        viewInfo = [[MCHFViewInfo alloc]init];
        viewInfo.viewId = viewId;
        viewInfo.aClass = aClass;
        viewInfo.viewHeight = viewHeight;
        [tableView.viewConfigDic setValue:viewInfo forKey:viewId];
    }
    if(isBiao)
    {
        viewInfo.viewHeight = viewHeight;
    }
    return viewInfo;
}


@end
